package com.rush.manageepac.service.impl;

import com.rush.manageepac.dao.ImplementDao;
import com.rush.manageepac.entity.Implement;
import com.rush.manageepac.service.intf.ImplementService;
import com.rush.manageepac.util.StringUtil;
import com.rush.manageepac.vo.PageBean;
import com.rush.manageepac.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @outher zhy
 * 2022-08-30
 */
@Service
public class ImplementServiceImpl implements ImplementService {
    @Autowired
    private ImplementDao dao;
    @Override
    public R save(Implement implement) {
        if (dao.save(implement)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int id) {
        if (dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(Implement implement) {
        if (dao.update(implement)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if (StringUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }
        int start=(page-1)*limit;
        return PageBean.ok(dao.selectCount(name),dao.selectPage(name,start,limit));
    }
    }

